package com.castle.fortress.admin.cms.fragment;

import com.castle.fortress.admin.cms.dto.CmsBannerDto;
import com.castle.fortress.admin.cms.service.CmsBannerService;
import com.castle.fortress.admin.utils.SpringUtils;
import org.beetl.core.tag.GeneralVarTagBinding;

import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

/**
 * cms 轮播图 标签
 * @author castle
 */
public class CmsBannerTag extends GeneralVarTagBinding {

	@Override
	public void render() {
		Map<String,Object> map = new HashMap<>();
		//轮播图标签
		if(containHtmlAttribute("tag")){
			map.put("tag",getAttributeValue("tag"));
		}
		//轮播图展示平台
		if(containHtmlAttribute("platform")){
			if("pc".equals(getAttributeValue("platform").toString().toLowerCase(Locale.ROOT))||"app".equals(getAttributeValue("platform").toString().toLowerCase(Locale.ROOT))){
				map.put("platform",getAttributeValue("platform"));
			}
		}
		CmsBannerService cmsBannerService = SpringUtils.getBean(CmsBannerService.class);
		List<CmsBannerDto> list = cmsBannerService.cmsTagListCmsBanner(map);
		this.binds(list);
		this.doBodyRender();
	}
}
